package com.xinke.module.system.convert.user;

import com.xinke.component.common.util.collection.CollectionUtils;
import com.xinke.component.common.util.object.BeanUtils;
import com.xinke.module.system.model.entity.user.AdminUserDO;
import com.xinke.module.system.model.entity.user.DeptDO;
import com.xinke.module.system.model.vo.user.AdminUserRespVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;
@Mapper
public interface UserConvert {
    UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);

    default List<AdminUserRespVO> convertList(List<AdminUserDO> list, Map<Long, DeptDO> deptMap) {
        return CollectionUtils.convertList(list, user -> convert(user, deptMap.get(user.getDeptId())));
    }
    default AdminUserRespVO convert(AdminUserDO user, DeptDO dept) {
        AdminUserRespVO userVO = BeanUtils.toBean(user, AdminUserRespVO.class);
        if (dept != null) {
            userVO.setDeptName(dept.getDeptName());
        }
        return userVO;
    }
}
